package com.hzhr.iot.device.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.constant.DeviceOptionsName;
import com.hzhr.iot.device.constant.DeviceOptionsTypeName;
import com.hzhr.iot.device.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.convertor.custom.CollectDeviceCustomConvertor;
import com.hzhr.iot.device.dao.CollectDeviceDao;
import com.hzhr.iot.device.dao.IotDeviceDao;
import com.hzhr.iot.device.model.collectDevice.CollectDeviceModel;
import com.hzhr.iot.device.model.collectDevice.CollectDevicePostModel;
import com.hzhr.iot.device.model.iotDevice.IotDeviceModel;
import com.hzhr.iot.device.model.pressureMonitor.*;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.device.service.helper.*;
import com.hzhr.iot.toll.sdk.model.gasUser.GasUserModel;
import com.hzhr.iot.toll.sdk.service.Toll_GasUserService;
import com.hzhr.iot.user.sdk.service.User_CompanyService;
import com.hzhr.iot.user.sdk.service.User_DeptService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class PressureMonitorService extends BaseService {
    @Autowired
    CollectDeviceCustomConvertor collectDeviceCustomConvertor;
    @Autowired
    CollectDeviceDao collectDeviceDao;
    @Autowired
    CollectDeviceService collectDeviceService;
    @Autowired
    User_DeptService user_deptService;
    @Autowired
    Toll_GasUserService toll_gasUserService;
    @Autowired
    IotDeviceService iotDeviceService;
    @Autowired
    User_CompanyService user_companyService;
    @Autowired
    CollectDataService collectDataService;
    @Autowired
    IotDeviceDao iotDeviceDao;
    @Autowired
    DeviceOptions deviceOptions;
    @Autowired
    IotDeviceTypeServiceHelper iotDeviceTypeServiceHelper;
    @Autowired
    IotDeviceServiceHelper iotDeviceServiceHelper;
    @Autowired
    CollectDeviceServiceHelper collectDeviceServiceHelper;
    @Autowired
    User_DeptServiceHelper user_deptServiceHelper;
    @Autowired
    Toll_GasUserServiceHelper toll_gasUserServiceHelper;

    //region javadoc注释 : post
    /**
     * 实施档案-创建流量计台账 <br/><br/>
     * 简介 : 创建压力监测仪采集台账；关联对应的物联台账及燃气用户 <br/>
     * 步骤 : <br/>
     * 1. 系统权限：根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在”；(√) <br/>
     * 2. 系统权限：根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“压力监测仪物联台账不存在”; (√) <br/>
     * 3. 系统权限：根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”存在，抛出异常“压力监测仪代码已存在”; (√) <br/>
     * 4. 系统权限：在燃气公司和部门下创建“压力监测仪采集台账_2”，并关联“压力监测仪物联台账_1”和“燃气用户_1”; (√) <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see PressureMonitorPostModel body <br/>
     * @see PressureMonitorPostResponseModel result <br/>
     */ 
    //endregion
    //region 说明 : post
    //实施档案-创建流量计台账
    //简介 : 创建压力监测仪采集台账；关联对应的物联台账及燃气用户
    //步骤 :
    //1. 系统权限：根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在”；(√)
    //2. 系统权限：根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“压力监测仪物联台账不存在”; (√)
    //3. 系统权限：根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”存在，抛出异常“压力监测仪代码已存在”; (√)
    //4. 系统权限：在燃气公司和部门下创建“压力监测仪采集台账_2”，并关联“压力监测仪物联台账_1”和“燃气用户_1”; (√)
    //endregion
    //region 参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/pressure-monitors", method = RequestMethod.POST)
    //endregion
    public PressureMonitorPostResponseModel post(Map<String, String> header, Map<String, Object> query,
                                                 PressureMonitorPostModel body) throws ServiceException {
        /* 系统权限：根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在” */
        String gasUserCode = body.getGasUserCode();
        Map<String, Object> getGasUserQuery = new HashMap<>();
        getGasUserQuery.put("_equal_companyId", body.getGasCompanyId());
        getGasUserQuery.put("_equal_code", gasUserCode);
        getGasUserQuery.put("_show", "one");
        getGasUserQuery.put("_show_info", true);
        GasUserModel gasUser_1 = toll_gasUserService.get(initHeader(header, AccessModeEnum.GLOBAL), getGasUserQuery).getModel();
        if (gasUser_1 == null) {
            throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_ADD_PRESSURE_METER_201);
        }

        /* 系统权限：根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“压力监测仪物联台账不存在” */
        String pressureMeterCode = body.getPressureMeterCode();
        IotDeviceModel pressureMeterIotRecord_1 = iotDeviceServiceHelper.getByCode(initHeader(header, AccessModeEnum.GLOBAL),pressureMeterCode);
        if (pressureMeterIotRecord_1 == null) {
            throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_ADD_PRESSURE_METER_202);
        }

        /* 系统权限：根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”存在，抛出异常“压力监测仪代码已存在” */
        Integer gasCompanyId = body.getGasCompanyId();
        String pressureMeterCollectCategoryCode = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.GAS_PRESSURE_MONITOR);
        int existCount = collectDeviceServiceHelper.getCountByCodeAndCompanyIdAndCategoryCode(initHeader(header, AccessModeEnum.GLOBAL),pressureMeterCode, gasCompanyId, pressureMeterCollectCategoryCode);
        if (existCount > 0) {
            throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_ADD_PRESSURE_METER_203);

        }

        /* 系统权限：在燃气公司和部门下创建“压力监测仪采集台账_2”，并关联“压力监测仪物联台账_1”和“燃气用户_1” */
        CollectDevicePostModel pressureMeterCollectRecord = new CollectDevicePostModel();
        pressureMeterCollectRecord.setCode(body.getPressureMeterCode());
        pressureMeterCollectRecord.setCategoryCode(deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GAS_PRESSURE_MONITOR"));
        pressureMeterCollectRecord.setTypeId(body.getPressureMeterTypeId());
        pressureMeterCollectRecord.setCompanyId(body.getGasCompanyId());
        pressureMeterCollectRecord.setDeptId(body.getDeptId());
        pressureMeterCollectRecord.setGasUserId(gasUser_1.getId());
        pressureMeterCollectRecord.setGasUserCode(gasUser_1.getCode());
        pressureMeterCollectRecord.setGasUserName(gasUser_1.getName());
        pressureMeterCollectRecord.setGasUserAddress(gasUser_1.getAddress());
        pressureMeterCollectRecord.setIotDeviceId(pressureMeterIotRecord_1.getId());
        Map<String, Object> postCollectDeviceQuery = new HashMap<>();
        //collectDeviceService.post(initHeader(header, AccessModeEnum.GLOBAL), postCollectDeviceQuery, pressureMeterCollectRecord);

        //返回
        String transactionId = getTransactionId(header);
        PressureMonitorPostResponseModel response = new PressureMonitorPostResponseModel();
        response.setTransactionId(transactionId);
        return response;
    }

    //region javadoc注释 : put
    /**
     * 实施档案-修改流量计台账 <br/><br/>
     * 简介 : 修改压力监测仪采集台账；关联对应的物联台账及燃气用户 <br/>
     * 步骤 : <br/>
     * 1. 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在”; (√) <br/>
     * 2. 系统权限：如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，则根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“新的压力检测物联台账不存在”，然后根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_2”，如果“压力监测仪采集台账_2”存在，则抛出异常“新的压力监测仪代码已存在”; (√) <br/>
     * 3. 系统权限：如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，则根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在”；(√) <br/>
     * 4. 系统权限：更新“压力监测仪采集台账_1”的信息，如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，关联“压力监测仪采集台账_1”和“压力监测仪物联台账_1”，如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，关联“压力监测仪采集台账_1”和“燃气用户_1”; (√) <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see PressureMonitorPutModel body <br/>
     * @see PressureMonitorPutResponseModel result <br/>
     */ 
    //endregion
    //region 说明 : put
    //实施档案-修改流量计台账
    //简介 : 修改压力监测仪采集台账；关联对应的物联台账及燃气用户
    //步骤 :
    //1. 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在”; (√)
    //2. 系统权限：如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，则根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“新的压力检测物联台账不存在”，然后根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_2”，如果“压力监测仪采集台账_2”存在，则抛出异常“新的压力监测仪代码已存在”; (√)
    //3. 系统权限：如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，则根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在”；(√)
    //4. 系统权限：更新“压力监测仪采集台账_1”的信息，如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，关联“压力监测仪采集台账_1”和“压力监测仪物联台账_1”，如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，关联“压力监测仪采集台账_1”和“燃气用户_1”; (√)
    //endregion
    //region 参数 : put
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : put
    @RequestMapping(value = "/pressure-monitors", method = RequestMethod.PUT)
    //endregion
    public PressureMonitorPutResponseModel put(Map<String, String> header, Map<String, Object> query,
                                               PressureMonitorPutModel body) throws ServiceException {
        /* 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如果“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在” */
        Integer pressureMeterId = body.getPressureMeterId();
        CollectDeviceModel pressureMeterCollectRecord_1 = collectDeviceServiceHelper.getById(initHeader(header, AccessModeEnum.GLOBAL), pressureMeterId);
        if (pressureMeterCollectRecord_1 == null) {
            throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_SET_PRESSURE_METER_201);
        }

        /* 系统权限：如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，则根据压力监测仪代码查询“压力监测仪物联台账_1”，如果“压力监测仪物联台账_1”不存在，抛出异常“新的压力检测物联台账不存在”，然后根据压力监测仪代码和燃气公司编号查询“压力监测仪采集台账_2”，如果“压力监测仪采集台账_2”存在，则抛出异常“新的压力监测仪代码已存在” */
        String pressureMeterCode = body.getPressureMeterCode();
        String pressureMeterCollectRecordCode_1 = pressureMeterCollectRecord_1.getCode();
        IotDeviceModel pressureMeterIotRecord_1 = null;
        if (!pressureMeterCode.equals(pressureMeterCollectRecordCode_1)) {
            pressureMeterIotRecord_1 = iotDeviceServiceHelper.getByCode(initHeader(header, AccessModeEnum.GLOBAL), pressureMeterCode);
            if (pressureMeterIotRecord_1 == null) {
                throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_SET_PRESSURE_METER_202);
            }

            Integer gasCompanyId = body.getGasCompanyId();
            String pressureMeterCollectCategoryCode = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.GAS_PRESSURE_MONITOR);
            int existCount = collectDeviceServiceHelper.getCountByCodeAndCompanyIdAndCategoryCode(initHeader(header, AccessModeEnum.GLOBAL), pressureMeterCode, gasCompanyId, pressureMeterCollectCategoryCode);
            if (existCount > 0) {
                throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_SET_PRESSURE_METER_203);
            }
        }

        /* 系统权限：如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，则根据燃气用户代码和部门编号查询“燃气用户_1”，如果“燃气用户_1”不存在，抛出异常“燃气用户不存在” */
        String gasUserCode = body.getGasUserCode();
        Integer deptId = body.getDeptId();
        String pressureMeterCollectRecordGasUserCode_1 = pressureMeterCollectRecord_1.getGasUserCode();
        GasUserModel gasUser_1 = null;
        if (!gasUserCode.equals(pressureMeterCollectRecordGasUserCode_1)) {
            gasUser_1 = toll_gasUserServiceHelper.getByCodeAndDeptId(initHeader(header, AccessModeEnum.GLOBAL), gasUserCode, deptId);
            if (gasUser_1 == null) {
                throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_SET_PRESSURE_METER_204);
            }
        }

        /* 系统权限：更新“压力监测仪采集台账_1”的信息，如果压力监测仪代码与“压力监测仪采集台账_1”的代码不同，关联“压力监测仪采集台账_1”和“压力监测仪物联台账_1”，如果燃气用户代码和“压力监测仪采集台账_1”的燃气用户代码不同，关联“压力监测仪采集台账_1”和“燃气用户_1” */
        Integer loginUserId = getUserId(header);
        CollectDeviceCustomQueryModel collectDeviceCustomQueryModel = new CollectDeviceCustomQueryModel();
        collectDeviceCustomQueryModel.setEqual_id(pressureMeterId);
        collectDeviceCustomQueryModel.setSet_code(pressureMeterCollectRecordCode_1);
        collectDeviceCustomQueryModel.setSet_typeId(pressureMeterCollectRecord_1.getTypeId());
        collectDeviceCustomQueryModel.setSet_companyId(body.getGasCompanyId());
        collectDeviceCustomQueryModel.setSet_deptId(body.getDeptId());
        if (!pressureMeterCode.equals(pressureMeterCollectRecordCode_1)) {
            collectDeviceCustomQueryModel.setSet_iotDeviceId(pressureMeterIotRecord_1.getId());
        }
        if (!gasUserCode.equals(pressureMeterCollectRecordGasUserCode_1)) {
            collectDeviceCustomQueryModel.setSet_gasUserId(gasUser_1.getId());
            collectDeviceCustomQueryModel.setSet_gasUserCode(gasUser_1.getCode());
            collectDeviceCustomQueryModel.setSet_gasUserName(gasUser_1.getName());
            collectDeviceCustomQueryModel.setSet_gasUserAddress(gasUser_1.getAddress());
        }
        collectDeviceCustomQueryModel.setSet_updateUserId(loginUserId);
        collectDeviceCustomQueryModel.setSet_updateTime(new Date());

        //返回
        String transactionId = getTransactionId(header);
        PressureMonitorPutResponseModel response = new PressureMonitorPutResponseModel();
        response.setTransactionId(transactionId);
        return response;
    }

    //region javadoc注释 : delete
    /**
     * 实施档案-删除压力检测仪台账 <br/><br/>
     * 简介 : 删除压力监测仪采集台账 <br/>
     * 步骤 : <br/>
     * 1. 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在”; (√) <br/>
     * 2. 系统权限：删除“压力监测仪采集台账_1”; (√) <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see PressureMonitorDeleteModel body <br/>
     * @see PressureMonitorDeleteResponseModel result <br/>
     */ 
    //endregion
    //region 说明 : delete
    //实施档案-删除压力检测仪台账
    //简介 : 删除压力监测仪采集台账
    //步骤 :
    //1. 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在”; (√)
    //2. 系统权限：删除“压力监测仪采集台账_1”; (√)
    //endregion
    //region 参数 : delete
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : delete
    @RequestMapping(value = "/pressure-monitors", method = RequestMethod.DELETE)
    //endregion
    public PressureMonitorDeleteResponseModel delete(Map<String, String> header, Map<String, Object> query,
                                                  PressureMonitorDeleteModel body) throws ServiceException {
        /* 系统权限：根据压力监测仪编号查询“压力监测仪采集台账_1”，如“压力监测仪采集台账_1”不存在，抛出异常“压力监测仪采集台账不存在” */
        Integer pressureMeterId = body.getPressureMonitorId();
        CollectDeviceModel pressureMeterCollectRecord_1 = collectDeviceServiceHelper.getById(initHeader(header, AccessModeEnum.GLOBAL), pressureMeterId);
        if (pressureMeterCollectRecord_1 == null) {
            throw new ServiceException(Device_ErrorsEnum.COLLECTDEVICESERVICE_IMPL_DEL_PRESSURE_METER_201);
        }

        /* 系统权限：删除“压力监测仪采集台账_1” */
        //collectDeviceService.deleteById(initHeader(header, AccessModeEnum.GLOBAL), pressureMeterId, new HashMap<>());

        //返回
        String transactionId = getTransactionId(header);
        PressureMonitorDeleteResponseModel response = new PressureMonitorDeleteResponseModel();
        response.setTransactionId(transactionId);
        return response;
    }

}

